<?php

abstract class HTMLElement {
	protected $value = null;
	protected $name = null;
	protected $id = null;
	protected $cssClass = null;
	protected $cssStyle = null;
	protected $onClick = null;
	protected $onMouseOver = null;
	protected $onMouseOut = null;
	protected $parent;
	protected $extraAttributes = array();
	/**
	 * @return unknown
	 */
	protected function getParent() {
		return $this->parent;
	}
	
	/**
	 * @param unknown_type $parent
	 */
	protected function setParent($parent) {
		$this->parent = $parent;
	}
	
	/**
	 * @return bool
	 */
	public function hasParent() {
		return ( bool ) (null != $this->parent);
	}
	
	abstract public function getHTML();
	/**
	 * @return unknown
	 */
	protected function _getOnClick() {
		return $this->onClick;
	}
	
	/**
	 * @param string $onClick
	 */
	protected function _setOnClick($onClick) {
		$this->onClick = $onClick;
	}
	
	/**
	 * @return string
	 */
	public function getCssClass() {
		return $this->cssClass;
	}
	
	/**
	 * @param string_type $cssClass
	 */
	public function setCssClass($cssClass) {
		$this->cssClass = $cssClass;
	}
	
	/**
	 *
	 * @return bool
	 */
	public function hasCssClass() {
		return ( bool ) (null != $this->cssClass);
	}
	/**
	 * @return CssStyle
	 */
	public function getCssStyle() {
		return $this->cssStyle;
	}
	
	/**
	 * @param CssStyle $cssStyle
	 */
	public function setCssStyle(CssStyle $cssStyle) {
		$this->cssStyle = $cssStyle;
	}
	
	/**
	 *
	 * @return bool
	 */
	public function hasCssStyle() {
		return ( bool ) (null != $this->cssStyle);
	}
	
	/**
	 * @return string
	 */
	public function getId() {
		return $this->id;
	}
	
	/**
	 * @param string_type $id
	 */
	public function setId($id) {
		$this->id = $id;
	}
	
	/**
	 *
	 * @return bool
	 */
	public function hasId() {
		return ( bool ) (null != $this->id);
	}
	
	/**
	 * @return string
	 */
	public function getName() {
		return $this->name;
	}
	
	/**
	 * @param string_type $name
	 */
	public function setName($name) {
		$this->name = $name;
	}
	
	/**
	 *
	 * @return bool
	 */
	public function hasName() {
		return ( bool ) (null != $this->name);
	}
	
	/**
	 * @return string
	 */
	public function getValue() {
		return $this->value;
	}
	
	/**
	 * @param string_type $value
	 */
	public function setValue($value) {
		$this->value = $value;
	}
	
	/**
	 *
	 * @return bool
	 */
	public function hasValue() {
		return ( bool ) (null != $this->value);
	}
	
	protected function has($property) {
		return ( bool ) (null != $this->$property);
	}

	/**
	 * @param unknown_type $extraAttributes
	 */
	public function setExtraAttribute($attribute, $value = '') {
		if(!$this->has($attribute))
		{
			$this->$attribute = $value;
			$this->extraAttributes[] = $attribute;
		}
		
	}
	
	protected function addAttributes($html, array $extraAttributes = array(), array $excludeAttributes = array()) {
		
		$defaultAttributes = array ('name', 'value', 'id' );
		$this->extraAttributes = array_merge($extraAttributes, $this->extraAttributes);
		$attributes = array_merge ( $defaultAttributes, $this->extraAttributes );
		
		foreach ( $attributes as $attribute ) {
			
			if (true == $this->has ( $attribute ) && false == in_array ( $attribute, $excludeAttributes )) {
				
				$html .= ' ' . $attribute .= '="' . $this->$attribute . '"';
			}
		}
		
		if (true == $this->hasCssClass () && false == in_array ( 'class', $excludeAttributes )) {
			$html .= ' ' . $this->cssClass->getStyleString ();
		}
		if (true == $this->hasCssStyle () && false == in_array ( 'style', $excludeAttributes )) {
			$html .= ' ' . $this->cssStyle->getStyleString ();
		}
		return $html;
	}

}

?>